package com.easyadmin.modules.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.modules.stock.domain.*;
import com.easyadmin.modules.stock.mapper.SysFuturesDayPriceDao;
import com.easyadmin.modules.stock.mapper.SysFuturesPriceReportDao;
import com.easyadmin.modules.stock.mapper.SysTradeDateDao;
import com.easyadmin.modules.stock.service.SysFuturesPriceReportService;
import com.easyadmin.modules.stock.vo.SyFuturesDayPriceVo;
import com.easyadmin.modules.stock.vo.SysTradeDateVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service("sysFuturesPriceReportService")
public class SysFuturesPriceReportServiceImpl  extends ServiceImpl<SysFuturesPriceReportDao, SysFuturesPriceReport>
        implements SysFuturesPriceReportService {

    @Resource
    SysFuturesPriceReportDao sysFuturesPriceReportDao;
    @Autowired
    SysTradeDateDao sysTradeDateDao;
    @Autowired
    private SysFuturesDayPriceDao sysFuturesDayPriceDao;


    @Override
    public PageInfo<SysFuturesPriceReport> queryPage(SysFuturesPriceReport sysFuturesEntity, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<SysFuturesPriceReport> data =sysFuturesPriceReportDao.selectList(new QueryWrapper<SysFuturesPriceReport>()
                .lambda().eq(StringUtils.isNotBlank(sysFuturesEntity.getStockCode()),
                        SysFuturesPriceReport::getStockCode,sysFuturesEntity.getStockCode())
                .like(StringUtils.isNotBlank(sysFuturesEntity.getStockName()),
                        SysFuturesPriceReport::getStockName,sysFuturesEntity.getStockName())
                .orderBy(true,false, SysFuturesPriceReport::getCreateTime));
        return new PageInfo<>(data);
    }


    /**
     * Describe: 先查询日期  根据开始日期和结束日期
     *
     *
     *
     *
     *
     */
    @Override
    public PageInfo<SyFuturesDayPriceVo> nqueryPage(SysReportVo sysReportVo, PageDomain pageDomain) {
        SysTradeDateVo data = sysTradeDateDao.selectMaxMinDate(sysReportVo.getStartDate(),
                sysReportVo.getEndDate());
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<SyFuturesDayPriceVo> list=new ArrayList<>();
        if(data!=null){
            //结束日期
            String maxDate=data.getMaxDate();
            //开始日期
            String minDate=data.getMinDate();
            list=sysFuturesDayPriceDao.querChange(minDate,maxDate,sysReportVo.getStockCode());
        }
         return new PageInfo<>(list);
    }
}
